<?php
class Login extends Controller {

       function __construct()
       {
            parent::Controller();
			$this->load->library('image');   //载入验证码库
       }

	   function index(){
		$data['baseurl']=base_url();
        $this->load->view('manage/login_view',$data);
		}
		    //登录验证函数
		function login_check(){
        $inputCode = $this->input->post('vdcode');
        //$inputCode=$_POST['imgcode'];
        //如果验证码输入正确，则继续判断
        if(($_SESSION['vdcode']!="")&&($inputCode == $_SESSION['vdcode'])){
            $input_username=$_POST['username'];
            $input_password=$_POST['password'];
            $this->load->model('user_model');          //载入用户模型
            $status=$this->user_model->admin_login_validate($input_username,$input_password);  //调用用户模型中的函数，并将参数传递过去
            switch($status) {
                case -1:
					$error['detail']="对不起，您输入的用户名不存在！";
					$error['min']=3;
					$error['url']= base_url()."manage/login";
                    $this->load->view('manage/errormsg_view',$error);
                    break;
				case 0:
					$_SESSION['admin_info']= $this->user_model->get_admin_info($input_username);//session写入管理员信息
					if($_SESSION['admin_info']['user_type']!=0) { //如果不是高级管理员
						$_SESSION['admin_info']['area'] = $this->user_model->get_area($_SESSION['admin_info']['user_areacode']);
						$msg['detail']="欢迎您".$_SESSION['admin_info']['user_truename']."，现在正在转入您所在的".$_SESSION['admin_info']['area']."分站！";
					}else{
						$_SESSION['admin_info']['area']='ALL';  //如果是高级管理员则设置地区为ALL
						$msg['detail']="欢迎您".$_SESSION['admin_info']['user_truename']."，现在正转入网站后台！";
					}
					$msg['min']=3;
					$msg['url']=base_url()."manage/cp";
                    $this->load->view('manage/message_view',$msg);
                    break;
                case 1:
                    $error['detail']="对不起，您的管理账号已被停用！";
					$error['min']=3;
					$error['url']="javascript:history.back(1)";
                    $this->load->view('manage/errormsg_view',$error);
                    break;
                case 2:
                    $error['detail']="对不起，您输入的密码错误！";
					$error['min']=3;
					$error['url']="javascript:history.back(1)";
                    $this->load->view('manage/errormsg_view',$error);
                    break;
            }
            //exit();
        }
        else{
            //如果验证码不正确，直接跳转到出错页面，并显示出错原因
            $error['detail']="您输入的验证码不正确，请重新输入。";
            $error['min']=3;
			$error['url']="javascript:history.back(1)";
            $this->load->view('manage/errormsg_view',$error);
        }

    }
}
?>